package com.bc.commoncore.sms;

import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import javax.xml.namespace.QName;

public class SmsWorkerApi {
	private ISmsWorker port = null;
	public SmsWorkerApi(String smsWorkerWcfUrl) throws Exception {
		URL wsdlURL = new URL(smsWorkerWcfUrl);
		SmsWorker ss = new SmsWorker(wsdlURL);
		port = ss.getBasicHttpBindingISmsWorker();
	}

	public String SendSms(String mobile, String content)
			throws UnsupportedEncodingException {
		if (mobile==null||mobile.isEmpty()||content==null||content.isEmpty()) {
			return "mobile或content不能为空";
		}
		if (port==null) {
			return "SmsWorkerApi没有初始化";
		}
		String gbMsg = URLEncoder.encode(content+"\n", "GBK");
		return port.send(mobile, gbMsg, "", "");
	}
}
